package formularios;

import dao.DevolucaoDAO;
import java.awt.Color;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import negocios.*;

public final class DevolucaoAluno extends javax.swing.JFrame {

    DefaultTableModel tmDevolucao = new DefaultTableModel(null, new String[]{"Aluno", "Serie", "Turma", "Livro", "Tombamento", "Data de saida", "Data de Entrega", "Id livro", "Id aluno"});
    List<Devolucao> Devolucao;
    ListSelectionModel lsmDevolucao;
    public DevolucaoAluno(){
        try {
            initComponents();
            setExtendedState(MAXIMIZED_BOTH);
            desabilita();
            listarDevolucao();
        } catch (SQLException ex) {
            Logger.getLogger(DevolucaoAluno.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jTF_pesquisar = new javax.swing.JTextField();
        jB_pesquisar = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jL_tombamento = new javax.swing.JLabel();
        jL_titulo = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTFTombamento = new javax.swing.JTextField();
        jTFTitulo = new javax.swing.JTextField();
        jTF_id_livro = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jL_aluno = new javax.swing.JLabel();
        jL_serie = new javax.swing.JLabel();
        jL_turma = new javax.swing.JLabel();
        jTFAluno = new javax.swing.JTextField();
        jTFSerie = new javax.swing.JTextField();
        jTFTurma = new javax.swing.JTextField();
        jTF_id_aluno = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jL_saida = new javax.swing.JLabel();
        jL_entrega = new javax.swing.JLabel();
        jTFDataSaida = new javax.swing.JTextField();
        jTFDataEntrega = new javax.swing.JTextField();
        jB_devolucao = new javax.swing.JButton();
        jB_voltar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jT_devolucao = new javax.swing.JTable();
        jPanel5 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jPanel8 = new javax.swing.JPanel();
        jPanel7 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();

        jLabel1.setText("jLabel1");

        jLabel5.setText("jLabel5");

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("SGB (Sistema Gerenciador da Biblioteca)");

        jPanel4.setBackground(new java.awt.Color(204, 255, 204));
        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 3, true), "Devolução do Livro", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12), new java.awt.Color(0, 102, 0))); // NOI18N

        jTF_pesquisar.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));
        jTF_pesquisar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTF_pesquisarActionPerformed(evt);
            }
        });
        jTF_pesquisar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTF_pesquisarKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTF_pesquisarKeyReleased(evt);
            }
        });

        jB_pesquisar.setBackground(new java.awt.Color(204, 255, 204));
        jB_pesquisar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Png/Figura1.PNG"))); // NOI18N
        jB_pesquisar.setText("Pesquisar");
        jB_pesquisar.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED, java.awt.Color.green, java.awt.Color.lightGray), new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 1, true)));
        jB_pesquisar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jB_pesquisarActionPerformed(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(204, 255, 204));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true), "Livro", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12), new java.awt.Color(0, 102, 0))); // NOI18N

        jL_tombamento.setText("Tombamento:");

        jL_titulo.setText("Título:");

        jTFTombamento.setFont(new java.awt.Font("Tahoma", 1, 12));
        jTFTombamento.setForeground(new java.awt.Color(0, 102, 0));
        jTFTombamento.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));

        jTFTitulo.setFont(new java.awt.Font("Tahoma", 1, 12));
        jTFTitulo.setForeground(new java.awt.Color(0, 102, 0));
        jTFTitulo.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));

        jTF_id_livro.setFont(new java.awt.Font("Tahoma", 1, 12));
        jTF_id_livro.setForeground(new java.awt.Color(0, 102, 0));
        jTF_id_livro.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));
        jTF_id_livro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTF_id_livroActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(184, 184, 184)
                        .addComponent(jLabel4))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jL_tombamento)
                            .addComponent(jL_titulo))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTFTitulo, javax.swing.GroupLayout.DEFAULT_SIZE, 279, Short.MAX_VALUE)
                            .addComponent(jTFTombamento, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap(347, Short.MAX_VALUE)
                        .addComponent(jTF_id_livro, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(48, 48, 48)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jL_tombamento)
                    .addComponent(jTFTombamento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jL_titulo)
                    .addComponent(jTFTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 65, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jTF_id_livro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel2.setBackground(new java.awt.Color(204, 255, 204));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true), "Aluno", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12), new java.awt.Color(0, 102, 0))); // NOI18N

        jL_aluno.setText("Aluno:");

        jL_serie.setText("Série:");

        jL_turma.setText("Turma:");

        jTFAluno.setFont(new java.awt.Font("Tahoma", 1, 12));
        jTFAluno.setForeground(new java.awt.Color(0, 102, 0));
        jTFAluno.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));

        jTFSerie.setFont(new java.awt.Font("Tahoma", 1, 12));
        jTFSerie.setForeground(new java.awt.Color(0, 102, 0));
        jTFSerie.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));

        jTFTurma.setFont(new java.awt.Font("Tahoma", 1, 12));
        jTFTurma.setForeground(new java.awt.Color(0, 102, 0));
        jTFTurma.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));

        jTF_id_aluno.setFont(new java.awt.Font("Tahoma", 1, 12));
        jTF_id_aluno.setForeground(new java.awt.Color(0, 102, 0));
        jTF_id_aluno.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap(72, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addComponent(jL_aluno)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jTFAluno, javax.swing.GroupLayout.PREFERRED_SIZE, 270, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                                .addComponent(jL_turma)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTFTurma, 0, 0, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                                .addComponent(jL_serie)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jTFSerie, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(jTF_id_aluno, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(43, 43, 43)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jL_aluno)
                    .addComponent(jTFAluno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jL_serie)
                    .addComponent(jTFSerie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTFTurma, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jL_turma))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
                .addComponent(jTF_id_aluno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel3.setBackground(new java.awt.Color(204, 255, 204));
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true), "Data", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12), new java.awt.Color(0, 102, 0))); // NOI18N

        jL_saida.setText("Data de Saída:");

        jL_entrega.setText("Data de Entrega:");

        jTFDataSaida.setFont(new java.awt.Font("Tahoma", 1, 12));
        jTFDataSaida.setForeground(new java.awt.Color(0, 102, 0));
        jTFDataSaida.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));

        jTFDataEntrega.setFont(new java.awt.Font("Tahoma", 1, 12));
        jTFDataEntrega.setForeground(new java.awt.Color(0, 102, 0));
        jTFDataEntrega.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jL_entrega)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTFDataEntrega))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jL_saida)
                        .addGap(18, 18, 18)
                        .addComponent(jTFDataSaida, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(114, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jL_saida)
                    .addComponent(jTFDataSaida, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jL_entrega)
                    .addComponent(jTFDataEntrega, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(114, Short.MAX_VALUE))
        );

        jB_devolucao.setBackground(new java.awt.Color(204, 255, 204));
        jB_devolucao.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Png/Figura5.png"))); // NOI18N
        jB_devolucao.setText("Realizar Devoluçao");
        jB_devolucao.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED, new java.awt.Color(0, 102, 0), java.awt.Color.white), new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 1, true)));
        jB_devolucao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jB_devolucaoActionPerformed(evt);
            }
        });

        jB_voltar.setBackground(new java.awt.Color(204, 255, 204));
        jB_voltar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Png/Figura6.png"))); // NOI18N
        jB_voltar.setText("Voltar");
        jB_voltar.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED, new java.awt.Color(0, 102, 0), java.awt.Color.white), new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 1, true)));
        jB_voltar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jB_voltarActionPerformed(evt);
            }
        });

        jScrollPane1.setBackground(new java.awt.Color(153, 255, 153));
        jScrollPane1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));
        jT_devolucao.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        lsmDevolucao = jT_devolucao.getSelectionModel();
        lsmDevolucao.addListSelectionListener(new ListSelectionListener(){
            public void valueChanged(ListSelectionEvent e){
                if(! e.getValueIsAdjusting()){
                    JTTabelaLinhaSelecionada(jT_devolucao);
                }
            }
        });

        jT_devolucao.setBackground(new java.awt.Color(204, 255, 204));
        jT_devolucao.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 1, true));
        jT_devolucao.setFont(new java.awt.Font("Tahoma", 1, 12));
        jT_devolucao.setForeground(new java.awt.Color(0, 102, 0));
        jT_devolucao.setModel(tmDevolucao);
        jT_devolucao.setGridColor(new java.awt.Color(0, 102, 0));
        jT_devolucao.setSelectionBackground(new java.awt.Color(204, 255, 204));
        jScrollPane1.setViewportView(jT_devolucao);

        jPanel5.setBackground(new java.awt.Color(204, 255, 204));
        jPanel5.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));

        jPanel6.setBackground(java.awt.Color.green);

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 16, Short.MAX_VALUE)
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 18, Short.MAX_VALUE)
        );

        jPanel8.setBackground(java.awt.Color.magenta);
        jPanel8.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.magenta));

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 14, Short.MAX_VALUE)
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 16, Short.MAX_VALUE)
        );

        jPanel7.setBackground(new java.awt.Color(255, 0, 0));

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 16, Short.MAX_VALUE)
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 18, Short.MAX_VALUE)
        );

        jLabel2.setText("No prazo");

        jLabel3.setText("Dia da entrega");

        jLabel6.setText("Atrazado");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel2))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel6))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel3)))
                .addContainerGap(32, Short.MAX_VALUE))
        );

        jPanel5Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jPanel6, jPanel7, jPanel8});

        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2)
                    .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel7, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );

        jPanel5Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jPanel6, jPanel7, jPanel8});

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 1289, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout.createSequentialGroup()
                        .addComponent(jTF_pesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, 1166, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jB_pesquisar, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout.createSequentialGroup()
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(366, 366, 366)
                        .addComponent(jB_voltar, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jB_devolucao, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(53, 53, 53)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 73, Short.MAX_VALUE)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTF_pesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jB_pesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 275, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(14, 14, 14)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jB_voltar, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jB_devolucao, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(45, 45, 45))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );

        jPanel4Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jB_devolucao, jB_voltar});

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-1333)/2, (screenSize.height-741)/2, 1333, 741);
    }// </editor-fold>//GEN-END:initComponents

    private void jB_voltarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jB_voltarActionPerformed
        dispose();
    }//GEN-LAST:event_jB_voltarActionPerformed

    private void jTF_pesquisarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTF_pesquisarActionPerformed
    }//GEN-LAST:event_jTF_pesquisarActionPerformed

    private void jTF_pesquisarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTF_pesquisarKeyPressed
    }//GEN-LAST:event_jTF_pesquisarKeyPressed

    private void jB_pesquisarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jB_pesquisarActionPerformed
        try {
            listarDevolucao();
        } catch (SQLException ex) {
            Logger.getLogger(DevolucaoAluno.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jB_pesquisarActionPerformed

    private void jB_devolucaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jB_devolucaoActionPerformed
        
        int resp = JOptionPane.showConfirmDialog(this, "Deseja realizar esta devolução ?",
                "Confirmação", JOptionPane.YES_NO_OPTION);
        if (resp == JOptionPane.YES_NO_OPTION) {
            try {
                
                cadastrar();
                listarDevolucao();
            } catch (SQLException ex) {
                Logger.getLogger(DevolucaoAluno.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_jB_devolucaoActionPerformed

    private void jTF_id_livroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTF_id_livroActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTF_id_livroActionPerformed

    private void jTF_pesquisarKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTF_pesquisarKeyReleased
        try {
            listarDevolucao();
        } catch (SQLException ex) {
            Logger.getLogger(DevolucaoAluno.class.getName()).log(Level.SEVERE, null, ex);
        }        // TODO add your handling code here:
    }//GEN-LAST:event_jTF_pesquisarKeyReleased

    protected void listarDevolucao() throws SQLException {
        DevolucaoDAO dao = new DevolucaoDAO();
        Devolucao = dao.Buscar(jTF_pesquisar.getText() + "%");
        mostraPesquisa(Devolucao);

    }

    private void mostraPesquisa(List<Devolucao> Devolucao) {

        while (tmDevolucao.getRowCount() > 0) {
            tmDevolucao.removeRow(0);
        }
        if (Devolucao.isEmpty()) {
        } else {
            String[] linha = new String[]{null, null, null, null, null, null, null, null, null};
            for (int i = 0; i < Devolucao.size(); i++) {
                tmDevolucao.addRow(linha);
                tmDevolucao.setValueAt(Devolucao.get(i).getNome(), i, 0);
                tmDevolucao.setValueAt(Devolucao.get(i).getSerie(), i, 1);
                tmDevolucao.setValueAt(Devolucao.get(i).getTurma(), i, 2);
                tmDevolucao.setValueAt(Devolucao.get(i).getTitulo(), i, 3);
                tmDevolucao.setValueAt(Devolucao.get(i).getNum(), i, 4);
                tmDevolucao.setValueAt(Devolucao.get(i).getData_saida(), i, 5);
                tmDevolucao.setValueAt(Devolucao.get(i).getData_devolucao(), i, 6);
                tmDevolucao.setValueAt(Devolucao.get(i).getId_livro(), i, 7);
                tmDevolucao.setValueAt(Devolucao.get(i).getId_aluno(), i, 8);

            }
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jB_devolucao;
    private javax.swing.JButton jB_pesquisar;
    private javax.swing.JButton jB_voltar;
    private javax.swing.JLabel jL_aluno;
    private javax.swing.JLabel jL_entrega;
    private javax.swing.JLabel jL_saida;
    private javax.swing.JLabel jL_serie;
    private javax.swing.JLabel jL_titulo;
    private javax.swing.JLabel jL_tombamento;
    private javax.swing.JLabel jL_turma;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTFAluno;
    private javax.swing.JTextField jTFDataEntrega;
    private javax.swing.JTextField jTFDataSaida;
    private javax.swing.JTextField jTFSerie;
    private javax.swing.JTextField jTFTitulo;
    private javax.swing.JTextField jTFTombamento;
    private javax.swing.JTextField jTFTurma;
    private javax.swing.JTextField jTF_id_aluno;
    private javax.swing.JTextField jTF_id_livro;
    private javax.swing.JTextField jTF_pesquisar;
    private javax.swing.JTable jT_devolucao;
    // End of variables declaration//GEN-END:variables

    public void JTTabelaLinhaSelecionada(JTable tabela) {

        if (jT_devolucao.getSelectedRow() > -1) {
            try {
                jTFTombamento.setText(String.valueOf(Devolucao.get(tabela.getSelectedRow()).getNum()));
                jTFTitulo.setText(String.valueOf(Devolucao.get(tabela.getSelectedRow()).getTitulo()));
                jTFAluno.setText(String.valueOf(Devolucao.get(tabela.getSelectedRow()).getNome()));
                jTFSerie.setText(String.valueOf(Devolucao.get(tabela.getSelectedRow()).getSerie()));
                jTFTurma.setText(String.valueOf(Devolucao.get(tabela.getSelectedRow()).getTurma()));
                jTFDataSaida.setText(String.valueOf(Devolucao.get(tabela.getSelectedRow()).getData_saida()));
                jTFDataEntrega.setText(String.valueOf(Devolucao.get(tabela.getSelectedRow()).getData_devolucao()));
                jTF_id_livro.setText(String.valueOf(Devolucao.get(tabela.getSelectedRow()).getId_livro()));
                jTF_id_aluno.setText(String.valueOf(Devolucao.get(tabela.getSelectedRow()).getId_aluno()));
                verificadata();
            } catch (ParseException ex) {
                Logger.getLogger(DevolucaoAluno.class.getName()).log(Level.SEVERE, null, ex);
            }

        } else {

            jTFTombamento.setText("");
            jTFTitulo.setText("");
            jTFAluno.setText("");
            jTFSerie.setText("");
            jTFTurma.setText("");
            jTFDataSaida.setText("");
            jTFDataEntrega.setText("");
            jTF_id_livro.setText("");
            jTF_id_aluno.setText("");

        }
    }

    private void cadastrar() throws SQLException {
        DevolucaoDAO a = new DevolucaoDAO();
        a.adicionar(Devolucao.get(jT_devolucao.getSelectedRow()));
        //Devolucao a = new Devolucao();
        //a.setId_aluno(Integer.parseInt(jTF_id_aluno.getText()));
        //a.setId_livro(Integer.parseInt(jTF_id_livro.getText()));
        //a.setData_saida(jTFDataSaida.getText());
        //a.setData_devolucao(jTFDataEntrega.getText());
    }

    public void verificadata() throws ParseException {
        java.util.Date mytec = new java.util.Date();
        SimpleDateFormat formataData = new SimpleDateFormat("yyyy-MM-dd");
        String data = formataData.format(mytec);
        if ((data).equals(jTFDataEntrega.getText())) {
            jT_devolucao.setSelectionBackground(Color.RED);
        } else {
            Date data_entrega = formataData.parse(jTFDataEntrega.getText());
            Date data_at = formataData.parse(data);
            Calendar calendar = GregorianCalendar.getInstance();
            calendar.setTime(data_at);
            calendar.roll(Calendar.DATE, 0);
            if (calendar.getTime().after(data_entrega))
            {
                jT_devolucao.setSelectionBackground(Color.MAGENTA);
            } else if (calendar.getTime().before(data_entrega)) {
                jT_devolucao.setSelectionBackground(Color.GREEN);
            }

        }
    }

    public void desabilita() {
        jTFTombamento.setEditable(false);
        jTFTitulo.setEditable(false);
        jTF_id_livro.setEditable(false);
        jTFAluno.setEditable(false);
        jTFSerie.setEditable(false);
        jTFTurma.setEditable(false);
        jTF_id_aluno.setEditable(false);
        jTFDataEntrega.setEditable(false);
        jTFDataSaida.setEditable(false);
    }
}